package com.rpframework.module.common.bottom.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rpframework.module.common.bottom.entity.Token;
import com.rpframework.module.common.bottom.mapper.TokenMapper;
import com.rpframework.module.common.bottom.service.TokenService;

import tk.mybatis.mapper.entity.Example;

/**
 * token表服务接口实现类 ClassName:TokenServiceImpl <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * Date: 2016年4月13日 下午3:14:38 <br/>
 *
 * @author Qiu ChengBing 745656220@qq.com
 * @since JDK 1.7
 */
@Service("tokenServiceImpl")
public class TokenServiceImpl extends BaseServiceImpl<Token> implements TokenService {

    public final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    TokenServiceImpl(TokenMapper tokenMapper) {
        super(tokenMapper);
    }

    @Override
    public Example getExample() {
        return new Example(Token.class);
    }

    /**
     * 查询accessToken TODO 简单描述该方法的实现功能（可选）.
     */
    @Override
    public String findAccessToken(String appId) {
        Token entity = new Token();
        entity.setAppId(appId);
        Token one = selectOne(entity);
        if (one != null) {
            return one.getAccessToken();
        } else {
            return null;
        }
    }

    /**
     * 查询ticket TODO 简单描述该方法的实现功能（可选）.
     */
    @Override
    public String findTicket(String appId) {
        Token entity = new Token();
        entity.setAppId(appId);
        Token one = selectOne(entity);
        if (one != null) {
            return one.getTicket();
        } else {
            return null;
        }
    }

    @Override
    public boolean insertTS(Token token) {
        Example example = getExample();
        example.createCriteria().andCondition("app_id=", token.getAppId());
        return updateByExampleSelective(token, example) > 0;
    }

}
